package com.skytech.chatim.sky.task;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;


/**
 * @author jason
 *
 */

public class ApiManager {
    private static ApiManager instantce = new ApiManager() ;
    public static ApiManager getInstances() {
        return instantce;
    }

    
    private  ApiManager() {
    }


    public AppServerResponse getResponse(Activity activity, AppServerRequest request) {
        String resposne =  NetworkHelper.getHttpResponse(activity, request);
        AppServerResponse appServerResponse = getResponse(resposne);
        appServerResponse.request = request ;
        return appServerResponse ;
    }




    private AppServerResponse getResponse(String resposne)  {
        AppServerResponse appServerResponse = new AppServerResponse();
        try {
            JSONObject response = new JSONObject(resposne);
            appServerResponse.code = response.optInt("code");
            appServerResponse.message = response.optString("message");
            appServerResponse.result = response.getJSONObject("result");
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return appServerResponse;
    }



    

}
